home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 285_03 / simple.prs < prev    next >
Encoding:
Text File  |  1990-07-08  |  11.1 KB  |  462 lines

  1. #line 2 "bison.simple"
  2.  
  3. /* Skeleton output parser for bison,
  4.    copyright (C) 1984 Bob Corbett and Richard Stallman
  5.  
  6.  
  7. /* This is the parser code that is written into each bison parser
  8.   when the %semantic_parser declaration is not specified in the grammar.
  9.   It was written by Richard Stallman by simplifying the hairy parser
  10.   used when %semantic_parser is specified.  */
  11.  
  12. /* Note: there must be only one dollar sign in this file.
  13.    It is replaced by the list of actions, each action
  14.    as one case of the switch.  */
  15.  
  16. #define yyerrok        (yyerrstatus = 0)
  17. #define yyclearin    (yychar = YYEMPTY)
  18. #define YYEMPTY        -2
  19. #define YYEOF        0
  20. #define YYFAIL        goto yyerrlab;
  21.  
  22. #define YYTERROR    1
  23.  
  24. #ifndef YYIMPURE
  25. extern int yylex( void) ;
  26. #define YYLEX        yylex()
  27. #endif
  28.  
  29. #ifndef YYPURE
  30. extern int yylex( YYLTYPE *, YYLTYPE *) ;
  31. #define YYLEX        yylex(&yylval, &yylloc)
  32. #endif
  33.  
  34. /* If nonreentrant, generate the variables here */
  35.  
  36. #ifndef YYIMPURE
  37.  
  38. int    yychar;            /*  the lookahead symbol        */
  39. YYSTYPE    yylval;            /*  the semantic value of the        */
  40.                 /*  lookahead symbol            */
  41.  
  42. YYLTYPE yylloc;            /*  location data for the lookahead    */
  43.                 /*  symbol                */
  44.  
  45. int yynerr;            /*  number of parse errors so far       */
  46.  
  47. #ifdef YYDEBUG
  48. int yydebug = 0;        /*  nonzero means print parse trace    */
  49. #endif
  50.  
  51. #endif  /* YYIMPURE */
  52.  
  53.  
  54. /*  YYMAXDEPTH indicates the initial size of the parser's stacks    */
  55.  
  56. #ifndef    YYMAXDEPTH
  57. #define YYMAXDEPTH 200
  58. #endif
  59.  
  60. /*  YYMAXLIMIT is the maximum size the stacks can grow to
  61.     (effective only if the built-in stack extension method is used).  */
  62.  
  63. #ifndef YYMAXLIMIT
  64. #define YYMAXLIMIT 10000
  65. #endif
  66.  
  67.  
  68. #line 167 "bison.simple"
  69. int
  70. yyparse()
  71. {
  72.   register int yystate;
  73.   register int yyn;
  74.   register short *yyssp;
  75.   register YYSTYPE *yyvsp;
  76.   YYLTYPE *yylsp;
  77.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  78.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  79.  
  80.   short    yyssa[YYMAXDEPTH];    /*  the state stack            */
  81.   YYSTYPE yyvsa[YYMAXDEPTH];    /*  the semantic value stack        */
  82.   YYLTYPE yylsa[YYMAXDEPTH];    /*  the location stack            */
  83.  
  84.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  85.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  86.   YYLTYPE *yyls = yylsa;
  87.  
  88.   int yymaxdepth = YYMAXDEPTH;
  89.  
  90. #ifndef YYPURE
  91.   int yychar;
  92.   YYSTYPE yylval;
  93.   YYLTYPE yylloc;
  94. #endif
  95.  
  96. #ifdef YYDEBUG
  97.   extern int yydebug;
  98. #endif
  99.  
  100.  
  101.   YYSTYPE yyval;        /*  the variable used to return        */
  102.                 /*  semantic values from the action    */
  103.                 /*  routines                */
  104.  
  105.   int yylen;
  106.  
  107. #ifdef YYDEBUG
  108.   if (yydebug)
  109.     fprintf(stderr, "Starting parse\n");
  110. #endif
  111.  
  112.   yystate = 0;
  113.   yyerrstatus = 0;
  114.   yynerr = 0;
  115.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  116.  
  117.   /* Initialize stack pointers.
  118.      Waste one element of value and location stack
  119.      so that they stay on the same level as the state stack.  */
  120.  
  121.   yyssp = yyss - 1;
  122.   yyvsp = yyvs;
  123.   yylsp = yyls;
  124.  
  125. /* Push a new state, which is found in  yystate  .  */
  126. /* In all cases, when you get here, the value and location stacks
  127.    have just been pushed. so pushing a state here evens the stacks.  */
  128. yynewstate:
  129.  
  130.   *++yyssp = yystate;
  131.  
  132.   if (yyssp >= yyss + yymaxdepth - 1)
  133.     {
  134.       /* Give user a chance to reallocate the stack */
  135.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  136.       YYSTYPE *yyvs1 = yyvs;
  137.       YYLTYPE *yyls1 = yyls;
  138.       short *yyss1 = yyss;
  139.  
  140.       /* Get the current used size of the three stacks, in elements.  */
  141.       int size = yyssp - yyss + 1;
  142.  
  143. #ifdef yyoverflow
  144.       /* Each stack pointer address is followed by the size of
  145.      the data in use in that stack, in bytes.  */
  146.       yyoverflow("parser stack overflow",
  147.          &yyss1, size * sizeof (*yyssp),
  148.          &yyvs1, size * sizeof (*yyvsp),
  149.          &yyls1, size * sizeof (*yylsp),
  150.          &yymaxdepth);
  151.  
  152.       yyss = yyss1; yyvs = yyvs1; yyls = yyls1;
  153. #else /* no yyoverflow */
  154.       /* Extend the stack our own way.  */
  155.       if (yymaxdepth >= YYMAXLIMIT)
  156.     yyerror("parser stack overflow");
  157.       yymaxdepth *= 2;
  158.       if (yymaxdepth > YYMAXLIMIT)
  159.     yymaxdepth = YYMAXLIMIT;
  160.       yyss = (short *) malloc (yymaxdepth * sizeof (*yyssp));
  161.       memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
  162.       yyvs = (YYSTYPE *) malloc (yymaxdepth * sizeof (*yyvsp));
  163.       memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
  164. #ifdef YYLSP_NEEDED
  165.       yyls = (YYLTYPE *) malloc (yymaxdepth * sizeof (*yylsp));
  166.       memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
  167. #endif
  168. #endif /* no yyoverflow */
  169.  
  170.       yyssp = yyss + size - 1;
  171.       yyvsp = yyvs + size - 1;
  172. #ifdef YYLSP_NEEDED
  173.       yylsp = yyls + size - 1;
  174. #endif
  175.  
  176. #ifdef YYDEBUG
  177.       if (yydebug)
  178.     fprintf(stderr, "Stack size increased to %d\n", yymaxdepth);
  179. #endif
  180.  
  181.       if (yyssp >= yyss + yymaxdepth - 1)
  182.     YYABORT;
  183.     }
  184.  
  185. #ifdef YYDEBUG
  186.   if (yydebug)
  187.     fprintf(stderr, "Entering state %d\n", yystate);
  188. #endif
  189.  
  190. /* Do appropriate processing given the current state.  */
  191. /* Read a lookahead token if we need one and don't already have one.  */
  192. yyresume:
  193.  
  194.   /* First try to decide what to do without reference to lookahead token.  */
  195.  
  196.   yyn = yypact[yystate];
  197.   if (yyn == YYFLAG)
  198.     goto yydefault;
  199.  
  200.   /* Not known => get a lookahead token if don't already have one.  */
  201.  
  202.   /* yychar is either YYEMPTY or YYEOF
  203.      or a valid token in external form.  */
  204.  
  205.   if (yychar == YYEMPTY)
  206.     {
  207. #ifdef YYDEBUG
  208.       if (yydebug)
  209.     fprintf(stderr, "Reading a token: ");
  210. #endif
  211.       yychar = YYLEX;
  212.     }
  213.  
  214.   /* Convert token to internal form (in yychar1) for indexing tables with */
  215.  
  216.   if (yychar <= 0)        /* This means end of input. */
  217.     {
  218.       yychar1 = 0;
  219.       yychar = YYEOF;        /* Don't call YYLEX any more */
  220.  
  221. #ifdef YYDEBUG
  222.       if (yydebug)
  223.     fprintf(stderr, "Now at end of input.\n");
  224. #endif
  225.     }
  226.   else
  227.     {
  228.       yychar1 = YYTRANSLATE(yychar);
  229.  
  230. #ifdef YYDEBUG
  231.       if (yydebug)
  232.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  233. #endif
  234.     }
  235.  
  236.   yyn += yychar1;
  237.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  238.     goto yydefault;
  239.  
  240.   yyn = yytable[yyn];
  241.  
  242.   /* yyn is what to do for this token type in this state.
  243.      Negative => reduce, -yyn is rule number.
  244.      Positive => shift, yyn is new state.
  245.        New state is final state => don't bother to shift,
  246.        just return success.
  247.      0, or most negative number => error.  */
  248.  
  249.   if (yyn < 0)
  250.     {
  251.       if (yyn == YYFLAG)
  252.     goto yyerrlab;
  253.       yyn = -yyn;
  254.       goto yyreduce;
  255.     }
  256.   else if (yyn == 0)
  257.     goto yyerrlab;
  258.  
  259.   if (yyn == YYFINAL)
  260.     YYACCEPT;
  261.  
  262.   /* Shift the lookahead token.  */
  263.  
  264. #ifdef YYDEBUG
  265.   if (yydebug)
  266.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  267. #endif
  268.  
  269.   /* Discard the token being shifted unless it is eof.  */
  270.   if (yychar != YYEOF)
  271.     yychar = YYEMPTY;
  272.  
  273.   *++yyvsp = yylval;
  274. #ifdef YYLSP_NEEDED
  275.   *++yylsp = yylloc;
  276. #endif
  277.  
  278.   /* count tokens shifted since error; after three, turn off error status.  */
  279.   if (yyerrstatus) yyerrstatus--;
  280.  
  281.   yystate = yyn;
  282.   goto yynewstate;
  283.  
  284. /* Do the default action for the current state.  */
  285. yydefault:
  286.  
  287.   yyn = yydefact[yystate];
  288.   if (yyn == 0)
  289.     goto yyerrlab;
  290.  
  291. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  292. yyreduce:
  293.   yylen = yyr2[yyn];
  294.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  295.  
  296. #ifdef YYDEBUG
  297.   if (yydebug)
  298.     {
  299.       if (yylen == 1)
  300.     fprintf (stderr, "Reducing 1 value via line %d, ",
  301.          yyrline[yyn]);
  302.       else
  303.     fprintf (stderr, "Reducing %d values via line %d, ",
  304.          yylen, yyrline[yyn]);
  305.     }
  306. #endif
  307.  
  308. $   /* the action file gets copied in in place of this dollarsign */
  309. #line 308 "bison.simple"
  310.  
  311.   yyvsp -= yylen;
  312.   yyssp -= yylen;
  313. #ifdef YYLSP_NEEDED
  314.   yylsp -= yylen;
  315. #endif
  316.  
  317. #ifdef YYDEBUG
  318.   if (yydebug)
  319.     {
  320.       short *ssp1 = yyss - 1;
  321.       fprintf (stderr, "state stack now");
  322.       while (ssp1 != yyssp)
  323.     fprintf (stderr, " %d", *++ssp1);
  324.       fprintf (stderr, "\n");
  325.     }
  326. #endif
  327.  
  328.   *++yyvsp = yyval;
  329.  
  330. #ifdef YYLSP_NEEDED
  331.   yylsp++;
  332.   if (yylen == 0)
  333.     {
  334.       yylsp->first_line = yylloc.first_line;
  335.       yylsp->first_column = yylloc.first_column;
  336.       yylsp->last_line = (yylsp-1)->last_line;
  337.       yylsp->last_column = (yylsp-1)->last_column;
  338.       yylsp->text = 0;
  339.     }
  340.   else
  341.     {
  342.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  343.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  344.     }
  345. #endif
  346.  
  347.   /* Now "shift" the result of the reduction.
  348.      Determine what state that goes to,
  349.      based on the state we popped back to
  350.      and the rule number reduced by.  */
  351.  
  352.   yyn = yyr1[yyn];
  353.  
  354.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  355.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  356.     yystate = yytable[yystate];
  357.   else
  358.     yystate = yydefgoto[yyn - YYNTBASE];
  359.  
  360.   goto yynewstate;
  361.  
  362. yyerrlab:   /* here on detecting error */
  363.  
  364.   if (! yyerrstatus)
  365.     /* If not already recovering from an error, report this error.  */
  366.     {
  367.       ++yynerr;
  368.       yyerror("parse error");
  369.     }
  370.  
  371.   if (yyerrstatus == 3)
  372.     {
  373.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  374.  
  375.       /* return failure if at end of input */
  376.       if (yychar == YYEOF)
  377.     YYABORT;
  378.  
  379. #ifdef YYDEBUG
  380.       if (yydebug)
  381.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  382. #endif
  383.  
  384.       yychar = YYEMPTY;
  385.     }
  386.  
  387.   /* Else will try to reuse lookahead token
  388.      after shifting the error token.  */
  389.  
  390.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  391.  
  392.   goto yyerrhandle;
  393.  
  394. yyerrdefault:  /* current state does not do anything special for the error token. */
  395.  
  396. #if 0
  397.   /* This is wrong; only states that explicitly want error tokens
  398.      should shift them.  */
  399.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  400.   if (yyn) goto yydefault;
  401. #endif
  402.  
  403. yyerrpop:   /* pop the current state because it cannot handle the error token */
  404.  
  405.   if (yyssp == yyss) YYABORT;
  406.   yyvsp--;
  407.   yystate = *--yyssp;
  408. #ifdef YYLSP_NEEDED
  409.   yylsp--;
  410. #endif
  411.  
  412. #ifdef YYDEBUG
  413.   if (yydebug)
  414.     {
  415.       short *ssp1 = yyss - 1;
  416.       fprintf (stderr, "Error: state stack now");
  417.       while (ssp1 != yyssp)
  418.     fprintf (stderr, " %d", *++ssp1);
  419.       fprintf (stderr, "\n");
  420.     }
  421. #endif
  422.  
  423. yyerrhandle:
  424.  
  425.   yyn = yypact[yystate];
  426.   if (yyn == YYFLAG)
  427.     goto yyerrdefault;
  428.  
  429.   yyn += YYTERROR;
  430.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  431.     goto yyerrdefault;
  432.  
  433.   yyn = yytable[yyn];
  434.   if (yyn < 0)
  435.     {
  436.       if (yyn == YYFLAG)
  437.     goto yyerrpop;
  438.       yyn = -yyn;
  439.       goto yyreduce;
  440.     }
  441.   else if (yyn == 0)
  442.     goto yyerrpop;
  443.  
  444.   if (yyn == YYFINAL)
  445.     YYACCEPT;
  446.  
  447. #ifdef YYDEBUG
  448.   if (yydebug)
  449.     fprintf(stderr, "Shifting error token, ");
  450. #endif
  451.  
  452.   *++yyvsp = yylval;
  453. #ifdef YYLSP_NEEDED
  454.   *++yylsp = yylloc;
  455. #endif
  456.  
  457.   yystate = yyn;
  458.   goto yynewstate;
  459. }
  460.  
  461.  
  462.